﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Abp.Domain.Repositories;
using Abp.Domain.Services;
using Abp.UI;
using FwProject.Core.SettlementInfoModel;

namespace FwProject.Manager
{
    public class SettlementInfoManager: IDomainService
    {
        private readonly IRepository<SettlementInfo, Guid> _settlementRepository;
        public SettlementInfoManager(IRepository<SettlementInfo, Guid> settlementRepository)
        {
            _settlementRepository = settlementRepository;

        }
        /// <summary>
        /// 添加一个结账订单
        /// </summary>
        /// <param name="settlement"></param>
        /// <returns></returns>
        public async Task<Guid> CreateSettlement(SettlementInfo settlement)
        {
            var model = _settlementRepository.GetAll().Where(o=>o.Id == settlement.Id).FirstOrDefault();
            if (model != null)
                throw new UserFriendlyException("该结账订单已存在");
            return await _settlementRepository.InsertAndGetIdAsync(settlement);
        }
        /// <summary>
        ///修改一个结账订单
        /// </summary>
        /// <param name="settlement"></param>
        /// <returns></returns>
        public async Task UpdateSettlement(SettlementInfo settlement)
        {

            await _settlementRepository.UpdateAsync(settlement);
        }
        /// <summary>
        ///  delete 一个结账订单
        /// </summary>
        /// <param name="settlement"></param>
        /// <returns></returns>
        public async Task DeleteSettlement(SettlementInfo settlement)
        {

            await _settlementRepository.DeleteAsync(settlement);
        }
    }
}
